﻿using System;
using System.IO;
using System.Text;
using System.Linq;
using System.Text.RegularExpressions;
using System.Collections.Generic;

/*
 * This file is part of FrequencyAnalyzer
 *    
 * Copyright 2014 Dr. Jason M Pittman. All Rights Reserved.
 * www.deceptikrons.org
 *
 * is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 2 of the License.
 *
 * is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with . If not, see <http://www.gnu.org/licenses>.
 */

namespace FrequencyAnalyzer
{
    class FileLoader
    {
        public Dictionary<char,int> LoadFile(string file)
        {
            string rawString = File.ReadAllText(file);

            string parsedString = Regex.Replace(rawString, @"[^\w\s]", string.Empty).ToUpper();

            var frequencies = parsedString
                .Where(c => Char.IsLetter(c))
                .GroupBy(c => c)
                .ToDictionary(g => g.Key, g => g.Count());
              
            return frequencies;
        }
    }
}
